const app = getApp();
Component({
  properties: {
    innerShow: {
      type:Boolean,
      value:false
    },
  },
  data: {
    title: "用户隐私保护提示",
    desc1: "感谢您使用本小程序，您使用本小程序前应当阅井同意",
    urlTitle: "《用户隐私保护指引》",
    desc2: "当您点击同意并开始时用产品服务时，即表示你已理解并同息该条款内容，该条款将对您产生法律约束力。如您拒绝，将无法进入小程序。",
    height: 0,
  },
  // lifetimes: {
  //   attached: function () {
  //     if (wx.getPrivacySetting) {
  //       wx.getPrivacySetting({
  //         success: res => {
  //           console.log("是否需要授权：", res.needAuthorization, "隐私协议的名称为：", res.privacyContractName)
  //           if (res.needAuthorization) {
  //             console.log(11111)
  //             this.popUp()
  //           } else {
  //             console.log(22222)
  //             this.disPopUp()
  //           }
  //         },
  //         fail: () => {},
  //         complete: () => {},
  //       })
  //     }
  //   },
  // },
  methods: {
    handleDisagree(e) {
      wx.exitMiniProgram()
     
    },
    handleAgree(e) {
      this.disPopUp()
      app.utils.getLocation().then(res => {
        wx.setStorageSync("locationBool", true);
        app.globalData.locationBool = true
        app.globalData.locationAuthorization = true;
        app.globalData.location = res;
        let json = {
          lat: res.latitude,
          lng: res.longitude,
          coordinate: "GCJ02",
        }
        // console.log(json)
        let jsonData = app.utils.getSignData(json);
        app.utils.post(app.api.reqUrls.getLocationInfo, jsonData).then(res => {
          if (res.status == 1) {
            app.globalData.address = res.result;
            app.globalData.address.select_store_id = app.globalData.nextdayStore != 0 ? app.globalData.nextdayStore : res.result.select_store_id;
            app.globalData.nextdayStore = res.result.crd_store_id;
            app.globalData.isjrdStore = true;
            app.globalData.tooFar = false;
            if (app.userAddressReadyCallback) {
              app.userAddressReadyCallback(res)
            }
            wx.switchTab({
              url: '/page/tabBar/index/index?location=true',
            })
          } else {
            throw res.msg
          }
        })

        console.log("app.js定位经纬度：", res);
      }).catch(err => {
        wx.setStorageSync("locationBool", true);
        app.globalData.locationBool = true;
        console.log(9999)
      })
    },
    showInfo(msg, confirmText = "我知道了", color = "#eb3223", callback = () => {}) {
      wx.showModal({
        content: msg.replace(/\\r\\n/g, "\n"),
        showCancel: false,
        confirmText: confirmText,
        confirmColor: color,
        success: callback()
      })
    },
    popUp() {
      this.setData({
        innerShow: true
      })
    },
    disPopUp() {

      this.setData({
        innerShow: false
      })
    },
    openPrivacyContract() {
      wx.openPrivacyContract({
        success: res => {
          console.log('openPrivacyContract success')
        },
        fail: res => {
          console.error('openPrivacyContract fail', res)
        }
      })
    }
  }
})